       ______  ___    ___  ______    _____       __   ___   __    ______
      |_    _| \  \  /  / |   _  \  |   __|     |  | |   \ |  |  /  ____\
        |  |    \  \/  /  |  |_|  | |  |__      |  | |    \|  | |  |___   
        |  |     \    /   |   ___/  |   __| --- |  | |        |  \___  \
        |  |      |  |    |  |      |  |__      |  | |  |\    |  ____|  |
        |__|      |__|    |__|      |_____|     |__| |__| \___| \______/

All set for Mandelbrot: a type-in on a fascinating frontier of maths, guided by
                                      RpM

In the age of the supercomputer whole new areas of problem-solving have been
invented because they're possible. Complex equations involving hundreds of
thousands of calculations have become manageable. What would have taken
hundreds of man-years to complete can take seconds on a powerful computer.
Several mathematicians' theories have been explored in depth as a result of the
computer. The Mandelbrot set - which stems from fractals - is both obscure and
spectacular. Much has been made of Benoit Mandelbrot and the set he discovered
in 1974. Why? Look at the colourful eye-catching designs of ever-increasing
complexity. No use whatsoever - but breathtaking.
    The Mandelbrot set is pictured as an area in two dimensions. It's a
collection of points defined by a simple repeated function. You can see the
complete Mandelbrot set in the picture - the black region. The coloured bands
represent the behaviour of points as they get close to the set.
    It's the complexity of the shape that makes the Mandelbrot set so
fascinating: the more you enlarge and examine minute areas of the set, the more
complex it gets. Although the area is finite - lies within the circle defined
by x + y = 4 (which I'm not going to prove, you can get further details from
Mandelbrot's book The Fractal Geometry of Nature) - the edge is infinitely
complex and of infinite length. Mathematicians have a word for this: fractal. A
few recent games use fractal graphics to build, say, a real-looking mountain
from only an equation. Eidolon and Koronis Rift are two.
    Enough of the background information. Let's get down to the nitty-gritty of
things. Here is a type-in that will produce the entire Mandelbrot set and the
other areas seen on this page.

[Screenshot of Mandelbrot Generator]
The complete Mandelbrot set

Mandelbrot Generator

    Alex Clark, the man from Lamlash in Strathclyde, is responsible for the
listing capable of producing the spectacular Mandelbrot set. (And thanks to all
the other readers who submitted versions as a result of Owen Cunningham's
letter in Reaction 21.) It has two ways of operation: automatic mode draws the
complete Mandelbrot set and six other interesting locations from the set;
manual mode lets you select and view an area of the set. In either case the
final design is saved to disk or cassette. It is best to run the program and
leave Arnold to do his bit for a day or so: each picture takes between three
and eight hours to produce.

[Listing - MANDGEN.BAS - lines 1-40]

Alex has been rather clever in the way he has used LEFT$ and LOWER$ in this
line. LEFT$(string expression, required length) is the standard format for the
command. Its function is to extract the number of characters from a string
(specified by required length) starting from the left of the string.

[Screenshot of Mandelbrot Generator]
A thermal map of the galaxy? The Norwegian coastline? Magnification of part of
the Mandelbrot set

    LOWER$ forces a string to lower-case - UPPER$ does the opposite. It is now
easy to see what line 30 does to your input - which is held in am$: the command
LEFT$(LOWER$(am$),1) = a will force am$ to lowercase and interest itself in the
leftmost character only. If the expression falls true, that is, finds that your
input consists of an a, you'll be whisked off to line 120; otherwise you're
banished to line 50.

Dicing with data

    Notice line 100, which reads a$="!"+a$. The filename is held in a$. The
exclamation mark prefixed to a$ prevents the SAVE message appearing on screen
(which would ruin five hours' computer time).

[Listing - lines 50-110]

    Once the program has accepted your input it will GOSUB 280 which does the
calculating, GOSUB 540 (draws up the picture and saves it) and finally RETURNs
whence it came.

[Listing - lines 120-270]

    If you picked automatic then you'll have landed here. Line 150 reads in the
data starting at 170 which holds the coordinates for the entire Mandelbrot set
and five other locations in and around the set. If you wish you can replace the
existing data with some of your own.
    The data is placed into arrays. Array xa will hold the six different j
values, ya the six k values and so on.
    Line 150 contains an interesting example of string-handling: a$ holds
!mandpic. However, there is a plus sign following the closing quotemark,
indicating more to a$ than is immediately obvious. The plus is followed by MID$
and a smattering of assorted characters. The function MID$ has the format
MID$(string variable, position, new string length). It behaves in a similar way
to LEFT$. The string variable in this case is STR$(pics). The variable pics
ranges from one to six (defined in the for-next loop, line 240). STR$ will
convert a numeric expression into string form. So the net result is that a$
will contain !mandpic1, with the final digit increasing each time until 6.

[Screenshot of Mandelbrot Generator]

Assigning variables

    The next section of the program is responsible for working out and storing
the different points of the Mandelbrot set. You should have no trouble
following this part. What you may not have come across is the form variable%.
The percent-sign tagged onto a Basic variable's name indicates a special type -
an integer variable. An integer is a whole number; it does not allow a
fractional part. There is a good reason for using this form of variable: it
takes up less space in memory and consequently increases execution speed.

[Listing - lines 280-530]

    The listing works out the points for the Mandelbrot set within an area 128
by 128. Each point is worked out individually - this amounts to an incredible
16,384 points to calculate. Given that each calculation with all its stages
takes approximately one second, it's easy to understand why Arnold needs five
hours to draw a single picture.

Drawing the set

    The data for the Mandelbrot set is stored from memory location &5000 (in
decimal, 20480). If a point is within the set it will have a value 255. The
nearer the point is to the set, the higher its value. Points of the same value
will have identical colours assigned to them, rather like contours on a map. In
theory there could be 256 colours in the final display, but in practice too
many colours would produce a confusing display. Not only that, the Amstrad can
display a maximum of only 16 colours. So we compromise: ranges of numbers will
have certain colours assigned to them.

[Listing - lines 540-920]

    Now, while waiting for your screen to fill, has anyone written a short,
fast machine-code version? Please send it in.

[There is a bug in Mandelbrot Generator. In automatic mode, the first of the
six pictures, which displays the entire Mandelbrot set, is not generated
correctly because the value of the real axis start is wrong. To correct this,
"-2.5,-1.25,2.5" in line 170 should be changed to "-2.0,-1.25,2.5". Amstrad
Action did not print a correction in any subsequent issues.

Amstrad Action also did not print the program for displaying the six pictures
once they have been saved to cassette or disc. It was published in the
September 1987 issue (#24).]

 _____________________________________________________________________________
|                                                                             |
|                                                                             |
|  Rally's wrong                                                              |
|                                                                             |
|  Issue 21 had a type-in called Rally. Unfortunately errors appeared in the  |
|  final listing. Luckily F Akinlawon (the author) spotted the mistakes.      |
|  Line 100 contains a bug which makes the game unplayable. Alter it to read  |
|  100 a$="^^". The up-arrow character is produced by pressing Control and K  |
|  simultaneously, and not by key marked up-arrow. Another bugette   which    |
|  won't seriously affect the gameplay   appears in line 480: the last Goto   |
|  in the line should read GOTO 50.                                           |
|                                                                             |
|_____________________________________________________________________________|
__   __             _
 |\  |  _  _ _ _ _   |__   __  _ __    ___  __  _ _ _   __
 | \ |  |  |  | | \  |  \ /__\  |     /  |  __\  | | \ /__\
_|_ \|  \__| _| | | _|__/ \__  _|_    \__| <__| _| | | \__
                                       __/

The computer will ask you to think of a number between 1 and 20 - mind you
don't spill the beans to Arnold. Once you have a number, the computer will
instruct you to perform several operations on it: addition and subtraction in
particular. Finally the computer will disclose the number in your mind. Magic?
No. See if you can work out how it does it. And the man to blame: Daniel Berman
of Liverpool.

[Listing - NUMGAME.BAS]

____
 |  \   __   ___ _ __  __   __   ___
 |   | /__\ /  |  |   /__\ /__\ <__
_|__/  \__  \__| _|_  \__  \__  ___>
             __/
                                      
 __   __  _ __  __  __  __  _ __  ___ _    __  _ __
/  \ /  \  |  \  \  /  /__\  |   <__   |  /  \  |  \
\__  \__/ _|_ |   \/   \__  _|_  ___> _|_ \__/ _|_ |

AE Turner of Hazlemere, Bucks, has sent in a program that converts between
Fahrenheit and Centigrade temperatures. This useful routine can quite easily be
incorporated into your own programs.

[Listing - DEGCONV.BAS]
 _____________________________________________________________________________
|  __  _                                          _                           |
| /  \  |__   __  _ __  __   __  _|_  __  _ __     |__  _  _                  |
||      |  \  __\  |    __\ /  \  |  /__\  |   __  |  \ \  / __               |
| \__/ _|_ | <__| _|_  <__| \__   \_ \__  _|_     _|__/  \/                   |
|                                                       _/                    |
|-----------------------------------------------------------------------------|
|     _                                                     .                 |
| __   |__   __  _ __  __   __  _|_  __  _ __   _ __  _ __ _   _ __  _|_      |
|/  \  |  \  __\  |    __\ /  \  |  /__\  |      |  \  |    |   |  \  |       |
|\__  _|_ | <__| _|_  <__| \__   \_ \__  _|_     |__/ _|_  _|_ _|_ |  \_      |
|                                               _|_                           |
|_____________________________________________________________________________|

Here's a handy routine from B Naff [If you're going to put silly names on your
communications, just remember that that's what will go on the cheque. Have you
tried convincing your bank that your name is Bug Navigator? - Ed] of Horsham,
West Sussex. It lets you print characters to the screen at the speed you choose
and makes a noise when a character appears - giving a typewriter effect.
    It should be very simple to tailor the routine and incorporate it within
your own programs: line 80 holds the delay between characters being printed -
alter it to suit. Text that you wish to appear must be held in Data statements
from lines 140 onwards. The final Data line must contain a single up-arrow
(found on the same key as the pound sign).

[Listing - CHRPRINT.BAS]

[The formatting of the text in the listing needs to be adjusted so that it is
aligned properly when it is displayed on the screen.]
____                       .
 |__>   __   __   __  _|_ _    __  _ __    _|_  __   ___ _|_  __  _ __
 | \   /__\  __\ /  \  |   |  /  \  |  \    |  /__\ <__   |  /__\  |
_|_ \_ \__  <__| \__   \_ _|_ \__/ _|_ |    \_ \__  ___>  \_ \__  _|_

Ever wanted to know how fast you are at slinging a gun? Here's your chance.
Kevin Stafferton of Spinney Hill, Northampton, has written a program that tests
your reaction speed.
    The program will display one of the four directional arrows. You must move
the joystick or press the cursor key corresponding to this arrow. The computer
times you and prints your speed with sarcastic remarks.
    As the program stands it uses the cursor keys. To use a joystick, remove
line 40 and de-REM (take out the command word "REM" - or the starting
apostrophe (') which means the same thing - from) line 45. The key numbers are
held in line 40. If you wish to use other key combinations look at the back of
the user guide or on the 6128's case; it contains all the key numbers. Line 40
contains c(1)=0. This means the key to move left is key number 0, which happens
to be the left-arrow character. If you wish this to be Z then replace it with
c(1)=71.The same applies for the other keys.
    By the way, a hot tip: note the way Kevin forces a new line in a Print
statement - like line 130 - by typing two quotemarks in a row.

[Listing - REACTION.BAS]
 _____________________________________________________________________________
|  __                _                                                        |
| /  \  __  _|_  __   |   __   ___ _  _  __    _|_  __                        |
||      __\  |   __\  |  /  \ /  | |  | /__\    |  /  \                       |
| \__/ <__|  \_ <__| _|_ \__/ \__| \__| \__     \_ \__/                       |
|                              __/                                            |
|-----------------------------------------------------------------------------|
|                   .       _     _                                           |
| __  __  __  _ __ _    __   |__   |   __   ___                               |
|  \  /   __\  |    |   __\  |  \  |  /__\ <__                                |
|   \/   <__| _|_  _|_ <__| _|__/ _|_ \__  ___>                               |
|_____________________________________________________________________________|

This program by Martin Packer of Greenford, Middlesex, will place the contents
of a disk catalogue into Basic variables. Ideal for incorporating into your own
programs so you can keep track of the disk's characteristics.
    To get the hang of the routine, run it several times with a disk in the
drive. After a few seconds, variable names, and their contents, will appear on
screen. Using it in your own listing shouldn't be too hard. Once you have the
variables assigned, you can use them, say, to build up a database containing
all relevant information on your disks.

[Listing - CAT2VARS.BAS]

 _____________________________________________________________________________
|____                                                                         |
| |  \   __   __   __  _ _ _  _ __  _ __  __   ___  ___                       |
| |   | /__\ /  \ /  \  | | \  |  \  |   /__\ <__  <__                        |
|_|__/  \__  \__  \__/ _| | |  |__/ _|_  \__  ___> ___>                       |
|                             _|_                                             |
|-----------------------------------------------------------------------------|
|       .                                                                     |
|_ __  _    __  _|_ _  _ _ __  __   ___                                       |
| |  \  |  /  \  |  |  |  |   /__\ <__                                        |
| |__/ _|_ \__   \_ \__| _|_  \__  ___>                                       |
|_|_                                                                          |
|_____________________________________________________________________________|

If you have played with Rainbird's Advanced OCP Art Studio, you'll know that
the picture can be compressed before saving. Unfortunately there is no way of
decompressing these pictures from Basic - a pity as they take up less than half
the ram-space of conventional screens.
    Stuart Lockey of Weybridge, Surrey, has come up with the answer: a program
to expand the compressed screens. There are two programs. The first, Writer,
writes and saves the code to do the expanding. Run the second listing which
loads the code as high in memory as possible. It also stores the Call address
in a variable, expand. All you have to do is load the compressed picture at
&4000 and CALL expand.

[Listing - WRITER.BAS]

[Listing - EXPANDER.BAS]


__      __  .         .               _               _
 |\    /|  _   __ __ _   _ __   ___    |__   __   ___  |__
 | \  / |   |   \_/   |   |  \ /  |    |  \  __\ <__   |  \
_|_ \/ _|_ _|_ _/ \_ _|_ _|_ | \__|   _|_ | <__| ___> _|_ |
                                __/
              _                            _
 __  _ __   __|   _ __   __  _  _ _ __   __|
 __\  |  \ /  |    |  \ /  \ |  |  |  \ /  |
<__| _|_ | \__|    |__/ \__/ \__| _|_ | \__|
                  _|_

T Lea of St Helens, Merseyside, has submitted a listing that solves the problem
of printing pound () and hash (#). The two characters have to share Ascii code
35. If you send a listing to the printer containing both, either the hashes
will come out as pounds or vice-versa, depending on what country you're set
for.
    The listing uses standard Epson codes and works with printers having a
choice of US and UK character sets. Make sure you have the dip-switches set to
the UK language set. The routine checks what is sent to the printer. If a hash
sign needs printing then T's program will switch to the US character set, print
the hash and revert to the UK set.
    You can use this routine from within Tasword (and from Protext, but its
Setprint function already takes care of the problem) - and of course from
Basic.

[Listing - PRINTCUR.BAS]

[There is a minor bug in Mixing Hash and Pound. The program does not adjust
HIMEM correctly, and the first byte above the previous value of HIMEM is
overwritten by the machine code routine, which is potentially a problem. To
correct this, "h=HIMEM-&98" in line 10 should be changed to "h=HIMEM-&99".
Amstrad Action did not print a correction in any subsequent issues.]

 _____________________________
|  ___  ___   ____   _______  |
|   |    |   /    \  |  |  |  |
|   |____|  |      |    |     |
|   |    |  |      |    |     |
|  _|_  _|_  \____/    _|_    |
|_____________________________|
 _____________________________
|  _______ ___ ______   ___   |
|  |  |  |  |   |    \ /   \  |
|     |     |   |____/ \___   |
|     |     |   |          \  |
|    _|_   _|_ _|_     \___/  |
|_____________________________|


Thrust scroll
Have you ever wondered how Firebird makes the screens in Thrust and Star
Firebirds scroll upwards? Well, here you have it in the form of a short
listing:

[Listing - THRUSTSC.BAS]

Patrick Connolly
Clogerhead, County Louth


Fuzz
How about this one-liner for some very odd on-screen effects?

[Listing - FUZZ.BAS]

David Bowman
Rotherham, S Yorkshire


Shaky sound
The small routine is useful for sprucing up your own program.
    Simply type it in and renumber to your liking. When run it will give an
explosion-like sound and the screen will judder realistically.

[Listing - SHAKY.BAS]

M Worsley
Fareham, Hants


Upside-down
If you want to play a joke on somebody try the listing below. Type it in and
run. It turns the character set upside-down. You can get back to normal by
entering SYMBOL AFTER 256.

[Listing - UPSIDE-D.BAS]

Paul Bower
Newbury, Berks


Format detecting
If you wish to determine the format of a disk run this program.

[Listing - FORMDET.BAS]

T Middelkamp
Holland


Dotty characters
Continuing with the crazy character fonts, here's a progette that gives you a
dotty character set. SYMBOL AFTER 256 switches off the effect.

[Listing - DOTTY.BAS]

Michael Unreadable Surname
Stanley, Co Durham
